


import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 佳宝活动
 *
 * allen  2023-12-19
 */

/**
 * 
 * oa活动管理列表
 * 
 */
const queryOaActivityList = (status, page, limit) => {
  return new Promise((resolve, reject) => {
    get("/api/front/oa/vote/activity/list?status=" + status + "&page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 创建活动
 * data:{
 *  
 * }
 */
const createActivityReq = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/oa/vote/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 更新活动
 * data:{
 *  
 * }
 */
const updateActivityReq = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/oa/vote/update", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 * 投票活动是否显示
 * data:{
 *  
 * }
 */
const showOrHideActivity = (data) => {
  return new Promise((resolve, reject) => {
    put("/api/front/oa/vote/isShow", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 删除活动
 * data:{
 *  
 * }
 */
const delActivityReq = (data) => {
  return new Promise((resolve, reject) => {
    put("/api/front/oa/vote/del", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * oa活动作品审核列表
 * 
 */
const queryWorksCheckList = (status, page, limit) => {
  return new Promise((resolve, reject) => {
    get("/api/front/oa/vote/examine/list?examineStatus=" + status + "&page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 
 * 审核作品 通过/失败
 * data:{
 *  
 * }
 */
const checkWorksReq = (data) => {
  return new Promise((resolve, reject) => {
    put("/api/front/oa/vote/examine", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * oa大学生身份认证
 * 
 */
const queryPersonCheckList = (page, limit) => {
  return new Promise((resolve, reject) => {
    get("/api/front/oa/student/auth/examine/list?page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 * 审核大学生认证
 * 
 */
const checkPersonReq = (data) => {
  return new Promise((resolve, reject) => {
    put("/api/front/oa/student/auth/examine", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}



/**
 * 
 * 提交大学生认证
 * data:{
 *  
 * }
 */
const submitPersonReq = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/user/student/auth/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 * 更新大学生认证
 * data:{
 *  
 * }
 */
const updatePersonReq = (data) => {
  return new Promise((resolve, reject) => {
    put("/api/front/user/student/auth/update", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 首页活动列表
 * status 0未开始  1进行中 2已结束
 */
const queryActivityList = (status, page, limit) => {
  return new Promise((resolve, reject) => {
    get("/api/front/vote/activity/list?status=" + status + "&page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 单个活动数据统计
 * 
 */
const activitySummaryReq = (id) => {
  return new Promise((resolve, reject) => {
    get("/api/front/vote/activity/summary?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 获取具体作品列表
 * 
 */
const queryWorksList = (page, limit, voteId, worksId = "") => {
  return new Promise((resolve, reject) => {
    get("/api/front/vote/works/list?page=" + page + "&limit=" + limit + "&voteId=" + voteId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 作品的投票记录
 * 
 */
const queryWorksVoteRecord = (page, limit, voteId, worksId) => {
  return new Promise((resolve, reject) => {
    get("/api/front/vote/record/list?page=" + page + "&limit=" + limit + "&voteId=" + voteId + "&worksId=" + worksId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 创建作品
 * 
 */
const createWorksReq = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/vote/works/create", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 * 更新作品
 * 
 */
const updateWorksReq = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/vote/works/update", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 * 投票接口
 * data:{
 *   voteId,
 *   worksId
 * }
 * 
 */
const voteReq = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/vote/works/vote", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 * 作品详情
 *
 *   worksId
 * 
 * 
 */
const worksDetailReq = (worksId) => {
  return new Promise((resolve, reject) => {
    get("/api/front/vote/works/detail?worksId=" + worksId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 *获取大学生认证信息
 */
const getPersonReq = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/user/student/auth/detail").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 
 *获取自己的作品
 */
const getMyWorksReq = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/vote/works/my?page=" + 1 + "&limit=" + 10).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}



module.exports = {
  queryOaActivityList, //oa活动管理列表
  createActivityReq,   //创建活动
  updateActivityReq,   //更新活动
  delActivityReq,      //删除活动
  queryWorksCheckList, //oa作品审核列表
  checkWorksReq,       //作品审核 通过/失败
  queryPersonCheckList, // oa大学生身份认证列表
  checkPersonReq,        //oa审核大学生身份
  submitPersonReq, //提交大学生认证
  getPersonReq,     //获取自己的认证信息
  updatePersonReq,       //更新大学生信息
  queryActivityList,     //首页活动列表
  queryWorksList,        //获取具体作品列表
  createWorksReq,        //创建作品
  updateWorksReq,        //更新作品
  voteReq,               //投票
  worksDetailReq,        //作品详情
  activitySummaryReq,    //单个活动统计总量
  queryWorksVoteRecord,   //作品的投票记录  
  getMyWorksReq,          //获取自己的作品
  showOrHideActivity,     //是否显示活动
}

